package org.gaaidou.ptarmigan.springboot.core.log;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.gaaidou.ptarmigan.springboot.core.async.ContextData;
import org.springframework.util.StringUtils;

public class LogPrefixConverter extends ClassicConverter {
    @Override
    public String convert(ILoggingEvent iLoggingEvent) {
        String txId = ContextData.getTxId();
        return String.format("%s-%s", Thread.currentThread().getName(), StringUtils.hasText(txId) ? "" : txId);
    }
}
